Author: fperrad
Date: Fri Mar 9 08:18:02 2007
New Revision: 17409
Modified:
trunk/languages/lua/luac.pir
trunk/languages/lua/src/ASTGrammar.tg
trunk/languages/lua/src/lua.pg
trunk/languages/lua/src/lua.pir
Log:
[Lua]
[perl #41684] [PATCH] Updates for lua
* I've tried to port some of the things done in Pynie to Lua (tree
transformations.)
It generates code now, but it's smelly. I'm really having trouble
understanding the parse tree, but it seems something's happening now as
it should.
* I renamed many rules in the grammar so the parse tree is a bit more
clear (when doing --target=PARSE)
* the compiler driver file is cleaned up.
* Still a lot of work to be done, but I think this is a step forward.
Courtesy of Klaas-Jan Stol <[EMAIL PROTECTED]>
Modified: trunk/languages/lua/luac.pir
==============================================================================
--- trunk/languages/lua/luac.pir (original)
+++ trunk/languages/lua/luac.pir Fri Mar 9 08:18:02 2007
@@ -18,14 +18,7 @@
.param pmc args
load_bytecode 'languages/lua/src/lua.pbc'
-
- # get program name for error reporting
- .local string prog
- prog = shift args
-
- # Sanity check parameters
- $I0 = args
- unless $I0 >= 1 goto ERR_TOO_FEW_ARGS
+ load_bytecode 'PGE/Dumper.pbc'
# Register the Lua compiler
$P0 = compreg 'Lua'
@@ -35,60 +28,8 @@
errs = new .Integer
set_root_global 'errors', errs
+ $P1 = $P0.'command_line'(args)
- # Process command line options
- load_bytecode "Getopt/Obj.pir"
-
- .local pmc getopts
- getopts = new "Getopt::Obj"
- getopts."notOptStop"(1)
- push getopts, "output|o=s"
- push getopts, "help|h"
- .local pmc opts
- opts = getopts."get_options"( args )
-
- # put back the program name
- unshift args, prog
-
- # handle help option
- .local string help
- help = opts['help']
- if help goto USAGE
-
- # handle target option
- .local string output
- output = opts['output']
- unless output goto OPTIONS_DONE
- if output == "PARSE" goto TARGET_PARSE
- if output == "PAST" goto TARGET_PAST
- if output == "PIRTIDY" goto TARGET_PIR
- if output == "PARSETREE" goto TARGET_PARSETREE
- goto ERR_UNKNOWN_TARGET
-
- OPTIONS_DONE:
-
- TARGET_PARSE:
- $P1 = $P0.'command_line'(args, 'target' => 'parse')
- goto DONE
-
- TARGET_PARSETREE:
- load_bytecode 'PGE/Dumper.pbc'
- load_bytecode 'dumper.pbc'
- $P1 = $P0.'command_line'(args, 'target' => 'parse')
- goto DONE
-
- TARGET_PAST:
- $P1 = $P0.'command_line'(args, 'target' => 'past')
- goto DONE
-
- TARGET_PIR:
- $P1 = $P0.'command_line'(args, 'target' => 'PIR')
- goto DONE
-
- ##COMPILE_AND_RUN:
- ## $P1 = $P0.'command_line'(args)
-
- DONE:
if errs > 0 goto ERR_MSG
print "Parse successful!\n"
.return($P1)
@@ -104,30 +45,16 @@
printerr "There was 1 error.\n"
end
- USAGE:
- printerr "Usage: "
- printerr prog
- printerr " [OPTIONS] FILE\n"
- printerr <<"OPTIONS"
- Options:
- --help -- print this message
- --output=TARGET -- specify target
- possible targets are:
- PARSE -- parse only (default)
- PAST -- print Parrot AST
- PIRTIDY -- print generated PIR code
- PARSETREE -- parse and print parse tree
-OPTIONS
- exit 1
-
- ERR_TOO_FEW_ARGS:
- printerr "Error: too few arguments\n"
- goto USAGE
- ERR_UNKNOWN_TARGET:
- printerr "Error: "
- printerr output
- printerr " is an unknown target\n"
- exit 1
+.end
+
+.namespace
+
+.sub 'listmaker'
+ .param pmc args :slurpy
+ unless null args goto have_args
+ args = new .ResizablePMCArray
+ have_args:
+ .return (args)
.end
=head1 LICENSE
Modified: trunk/languages/lua/src/ASTGrammar.tg
==============================================================================
--- trunk/languages/lua/src/ASTGrammar.tg (original)
+++ trunk/languages/lua/src/ASTGrammar.tg Fri Mar 9 08:18:02 2007
@@ -1,5 +1,5 @@
-grammar ASTGrammar is TGE::Grammar;
+grammar Lua::PAST::Grammar is TGE::Grammar;
transform past (ROOT) :language('PIR') {
@@ -32,75 +32,54 @@
goto iter_loop
iter_end:
- # $P0 = node['laststat']
- # if null $P0 goto no_last_stat
- # $P1 = tree.'get'('past', $P0, 'Lua::Grammar::laststat')
- # past.'push'($P1)
- # no_last_stat:
+ $P0 = node['last_statement']
+ if null $P0 goto no_last_stat
+ $P1 = tree.'get'('past', $P0, 'Lua::Grammar::last_statement')
+ past.'push'($P1)
+ no_last_stat:
.return (past)
}
transform past (Lua::Grammar::statement) :language('PIR') {
- ifstat:
- $P0 = node['ifstat']
- if null $P0 goto whilestat
- .return tree.'get'('past', $P0, 'Lua::Grammar::ifstat')
- whilestat:
- $P0 = node['whilestat']
- if null $P0 goto doblock
- .return tree.'get'('past', $P0, 'Lua::Grammar::whilestat')
- doblock:
- $P0 = node['do']
- if null $P0 goto forstat
- .return tree.'get'('past', $P0, 'Lua::Grammar::block')
- forstat:
- $P0 = node['forstat']
- if null $P0 goto repeatstat
- .return tree.'get'('past', $P0, 'Lua::Grammar::forstat')
- repeatstat:
- $P0 = node['repeatstat']
- if null $P0 goto localstat
- .return tree.'get'('past', $P0, 'Lua::Grammar::repeatstat')
- localstat:
- $P0 = node['localstat']
- if null $P0 goto exprstat
- .return tree.'get'('past', $P0, 'Lua::Grammar::localstat')
- exprstat:
- $P0 = node['exprstat']
- if null $P0 goto funcstat
- .return tree.'get'('past', $P0, 'Lua::Grammar::exprstat')
- funcstat:
- $P0 = node['funcstat']
- if null $P0 goto error
- .return tree.'get'('past', $P0, 'Lua::Grammar::funcstat')
- error:
- printerr "Unknown type of statement"
- exit 1
+ $S0 = node.'find_key'()
+ $P0 = node[$S0]
+ $S0 = concat 'Lua::Grammar::', $S0
+ .return tree.'get'('past', $P0, $S0)
}
-transform past (Lua::Grammar::laststat) :language('PIR') {
- .local pmc past
+transform past (Lua::Grammar::last_statement) :language('PIR') {
+ .local pmc past, cnode
returnstat:
- $P0 = node['return']
- if null $P0 goto breakstat
+ cnode = node['return']
+ if null cnode goto breakstat
+
.local pmc exprpast
past = new 'PAST::Op'
- past.'init'('node'=>node)
- $P0 = node['explist1']
- if null $P0 goto no_return_values
- exprpast = tree.'get'('past', $P0, 'Lua::Grammar::explist1')
- past.'push'(exprpast)
+ past.'init'('node'=>cnode, 'pasttype'=>'pirop', 'pirop'=>'return')
+
+ cnode = node['expression_list']
+ #S0 = typeof cnode
+ #printerr S0
+ if null cnode goto no_return_values
+ exprpast = tree.'get'('past', cnode, 'Lua::Grammar::expression_list')
+ #past.'push'(exprpast)
no_return_values:
.return (past)
breakstat:
+ cnode = node['break']
+ if null cnode goto no_stat
past = new 'PAST::Op'
past.'init'('node'=>node, 'pasttype'=>'pirop', 'pirop'=>'goto')
.return (past)
+
+ no_stat:
+ printerr "no last statement\n"
+ exit 1
}
-transform past (Lua::Grammar::ifstat) :language('PIR') {
+transform past (Lua::Grammar::if_stat) :language('PIR') {
.local pmc past
# create the PAST node for an if statement
@@ -109,8 +88,8 @@
.local pmc condnode, condpast
# get the PAST node for the condition
- condnode = node['expr1']
- condpast = tree.'get'('past', condnode, 'Lua::Grammar::expr1')
+ condnode = node['expression']
+ condpast = tree.'get'('past', condnode, 'Lua::Grammar::expression')
past.'push'(condpast)
.local pmc ifnode, ifpast
@@ -121,15 +100,15 @@
.local pmc elseifnode, elseifpast
# get the elseifblock nodes
- elseifnode = node['elseifblocks']
+ elseifnode = node['elseif_block']
if null elseifnode goto skip_elseifs
- elseifpast = tree.'get'('past', elseifnode, 'Lua::Grammar::elseifblocks')
+ elseifpast = tree.'get'('past', elseifnode, 'Lua::Grammar::elseif_block')
past.'push'(elseifpast)
skip_elseifs:
.local pmc elsenode, elsepast
# get the elseblock nodes
- elsenode = node['elseblock']
+ elsenode = node['else_block']
if null elsenode goto skip_else
elsepast = tree.'get'('past', elsenode, 'Lua::Grammar::block')
past.'push'(elsepast)
@@ -138,16 +117,16 @@
.return (past)
}
-transform past (Lua::Grammar::elseifblocks) :language('PIR') {
+transform past (Lua::Grammar::elseif_block) :language('PIR') {
.local pmc past, iter
- $P0 = node['elseifblock']
+ $P0 = node['elseif_block']
iter = new .Iterator, $P0
iter_loop:
unless iter goto iter_end
.local pmc cnode, cpast
cnode = shift iter
- cpast = tree.'get'('past', cnode, 'Lua::Grammar::elseifblock')
+ cpast = tree.'get'('past', cnode, 'Lua::Grammar::elseif_block')
past.'push'(cpast)
goto iter_loop
iter_end:
@@ -155,15 +134,15 @@
.return (past)
}
-transform past (Lua::Grammar::elseifblock) :language('PIR') {
+transform past (Lua::Grammar::elseif_block) :language('PIR') {
.local pmc past
past = new 'PAST::Op'
past.'init'('node'=>node, 'pasttype'=>'if')
.local pmc condnode, condpast
- condnode = node['expr1']
- condpast = tree.'get'('past', condnode, 'Lua::Grammar::expr1')
+ condnode = node['expression']
+ condpast = tree.'get'('past', condnode, 'Lua::Grammar::expression')
past.'push'(condpast)
.local pmc ifnode, ifpast
@@ -174,44 +153,21 @@
.return (past)
}
-transform past (ABC::Grammar::if_statement) :language('PIR') {
- .local pmc exprnode, thennode, elsenode
- exprnode = node['expression']
- $P0 = node['statement']
- thennode = $P0[0]
- elsenode = $P0[1]
-
- .local pmc past
- past = new 'PAST::Op'
- past.'init'('node'=>node, 'pasttype'=>'if')
- .local pmc exprpast, thenpast, elsepast
- exprpast = tree.'get'('past', exprnode, 'ABC::Grammar::expression')
- past.'push'(exprpast)
- thenpast = tree.'get'('past', thennode, 'ABC::Grammar::statement')
- past.'push'(thenpast)
- $I0 = defined elsenode
- if $I0 == 0 goto done_else
- elsepast = tree.'get'('past', elsenode, 'ABC::Grammar::statement')
- past.'push'(elsepast)
- done_else:
- .return (past)
-}
-
-transform past (Lua::Grammar::localstat) :language('PIR') {
+transform past (Lua::Grammar::local_stat) :language('PIR') {
.local pmc past
past = new 'PAST::Var'
past.'init'('node'=>node)
.return (past)
}
-transform past (Lua::Grammar::whilestat) :language('PIR') {
+transform past (Lua::Grammar::while_stat) :language('PIR') {
.local pmc past
past = new 'PAST::Op'
past.'init'('node'=>node, 'pasttype'=>'while')
.local pmc condnode, condpast
- condnode = node['expr1']
- condpast = tree.'get'('past', condnode, 'Lua::Grammar::expr1')
+ condnode = node['expression']
+ condpast = tree.'get'('past', condnode, 'Lua::Grammar::expression')
past.'push'(condpast)
.local pmc blocknode, blockpast
@@ -222,14 +178,14 @@
.return (past)
}
-transform past (Lua::Grammar::repeatstat) {
+transform past (Lua::Grammar::repeat_stat) {
.local pmc past
past = new 'PAST::Op'
past.'init'('node'=>node)
.local pmc exprnode, exprpast
- exprnode = node['expr1']
- exprpast = tree.'get'('past', exprnode, 'Lua::Grammar::expr1')
+ exprnode = node['expression']
+ exprpast = tree.'get'('past', exprnode, 'Lua::Grammar::expression')
.local pmc blocknode, blockpast
blocknode = node['block']
@@ -239,7 +195,7 @@
.return (past)
}
-transform past (Lua::Grammar::forstat) :language('PIR') {
+transform past (Lua::Grammar::for_stat) :language('PIR') {
.local pmc past
fornum:
$P0 = node['fornum']
@@ -266,35 +222,59 @@
}
-
-transform past (Lua::Grammar::retstat) :language('PIR') {
- .local pmc past
+transform past (Lua::Grammar::expression_stat) :language('PIR') {
+ .local pmc past, primpast
past = new 'PAST::Op'
- past.'init'('node'=>node)
+ $P0 = node['primary_expression']
+ primpast = tree.'get'('past', $P0, 'Lua::Grammar::primary_expression')
+ past.'push'(primpast)
+
+ assignment:
+ .local pmc assignpast
+ $P0 = node['assignment']
+ if null $P0 goto function_call
+ assignpast = tree.'get'('past', $P0, 'Lua::Grammar::assignment')
+ past.'push'(assignpast)
+
+ function_call:
+
+ .local pmc callnode, callpast
+ callnode = node['function_args']
+ if null callnode goto no_funcargs
+ callpast = tree.'get'('past', callnode, 'Lua::Grammar::function_args')
+ if null callpast goto no_funcargs
+ .return (past)
+
+ no_funcargs:
.return (past)
}
-transform past (Lua::Grammar::exprstat) :language('PIR') {
- .local pmc past
- past = new 'PAST::Op'
- $P0 = node['primaryexp']
+transform past (Lua::Grammar::assignment) :language('PIR') {
+ $P0 = node['expression_list']
+
+ if null $P0 goto more_expr
+ .return tree.'get'('past', $P0, 'Lua::Grammar::expression_list')
+ more_expr:
+ printerr "Not implemented\n"
+ exit 1
- .return (past)
}
-transform past (Lua::Grammar::funcargs) :language('PIR') {
- .local pmc past
- past = new 'PAST::Val'
- .return (past)
+transform past (Lua::Grammar::function_args) :language('PIR') {
+ node = node[0]
+ $S0 = node.'find_key'()
+ $P0 = node[$S0]
+ $S0 = concat 'Lua::Grammar::', $S0
+ .return tree.'get'('past', $P0, $S0)
}
-transform past (Lua::Grammar::funcstat) :language('PIR') {
+transform past (Lua::Grammar::function_stat) :language('PIR') {
.local pmc past
past = new 'PAST::Op'
past.'init'('node'=>node, 'pasttype'=>'assign')
.local pmc bodynode, bodypast
- bodynode = node['body']
- bodypast = tree.'get'('past', bodynode, 'Lua::Grammar::body')
+ bodynode = node['function_body']
+ bodypast = tree.'get'('past', bodynode, 'Lua::Grammar::function_body')
past.'push'(bodypast)
.return (past)
}
@@ -304,7 +284,7 @@
#
# Store each of the instructions in a body node in a PAST::Stmts node.
#
-transform past (Lua::Grammar::body) :language('PIR') {
+transform past (Lua::Grammar::function_body) :language('PIR') {
.local pmc past
past = new 'PAST::Block'
past.'init'('node'=>node)
@@ -320,150 +300,152 @@
.return (past)
}
-transform past (Lua::Grammar::param) :language('PIR') {
- .local pmc past, name
+transform past (Lua::Grammar::name) :language('PIR') {
+ .local pmc past
+ $S0 = node
past = new 'PAST::Var'
-
- past.'init'('node'=>node, 'scope'=>'parameter', 'name'=>name)
+ past.'init'('node'=>node, 'name'=>$S0, 'scope'=>'package')
.return (past)
}
-
-
-
-transform past (Lua::Grammar::name) :language('PIR') {
+transform past (Lua::Grammar::constructor) :language('PIR') {
.local pmc past
past = new 'PAST::Var'
past.'init'('node'=>node)
.return (past)
}
-transform past (Lua::Grammar::number) :language('PIR') {
- .local pmc past, lhs
- past = new 'PAST::Val'
- past.'init'('node'=>node)
- .return (past)
-}
+transform past (Lua::Grammar::expression_list) :language('PIR') {
+ .local pmc past
+ past = new 'PAST::Op'
+ past.'init'('node'=>node, 'name'=>'listmaker')
+ .local pmc expriter
-transform past (Lua::Grammar::prefixexp) :language('PIR') {
- .local pmc past, lhs
- past = new 'PAST::Var'
- past.'init'('node'=>node)
- .return (past)
-}
+ #$S0 = node.'find_key'()
+ #printerr $S0
-transform past (Lua::Grammar::primaryxexp) :language('PIR') {
- .local pmc past, lhs
- past = new 'PAST::Var'
- past.'init'('node'=>node)
- .return (past)
-}
+ $P0 = node['expression_list']
-transform past (Lua::Grammar::constructor) :language('PIR') {
- .local pmc past
- past = new 'PAST::Var'
- past.'init'('node'=>node)
+ if null $P0 goto error
+ #printerr $S0
+ #printerr "\n"
+
+ $P0 = $P0['expression']
+ expriter = new .Iterator, $P0
+
+ iter_loop:
+ unless expriter goto iter_end
+ .local pmc enode, epast
+ enode = shift expriter
+ epast = tree.'get'('past', enode, 'Lua::Grammar::expression')
+ past.'push'(epast)
+ goto iter_loop
+ iter_end:
.return (past)
+ error:
+ printerr "null access in expr list\n"
+ exit 1
}
-
-transform past (Lua::Grammar::expr1) :language('PIR') {
+transform past (Lua::Grammar::expression) :language('PIR') {
$P0 = node['expr']
- #.return tree.'get'('past', $P0, 'Lua::Grammar::simpleexpr')
- .local pmc past
- past = new 'PAST::Val'
- .return (past) ## FIX
+ .return tree.'get'('past', $P0, 'Lua::Grammar::expr')
}
-transform past (Lua::Grammar::simpleexpr) :language('PIR') {
- .local pmc past
- number:
- $P0 = node['number']
- if null $P0 goto stringexpr
- past = new 'PAST::Val'
- past.'init'()
- .return (past)
- stringexpr:
- $P0 = node['string']
- if null $P0 goto nilexpr
- .return tree.'get'('past', $P0, 'Lua::Grammar::string')
- nilexpr:
- $P0 = node['nil']
- if null $P0 goto trueexpr
- past = new 'PAST::Val'
- past.'init'()
- .return (past)
- trueexpr:
- $P0 = node['true']
- if null $P0 goto falseexpr
- past = new 'PAST::Val'
- past.'init'()
- .return (past)
- falseexpr:
- $P0 = node['false']
- if null $P0 goto vararg
- past = new 'PAST::Val'
- past.'init'()
- .return (past)
- vararg:
- $P0 = node['...']
- if null $P0 goto function
- past = new 'PAST::Val'
- past.'init'()
+transform past (Lua::Grammar::expr) :language('PIR') {
+ .local string type
+ type = node['type']
+
+ if type == 'term:' goto past_term
+
+ .local pmc optable, optok
+ .local string pasttype, pirop, returns
+ .local int islvalue
+ optable = get_hll_global [ 'Lua::Grammar' ], '$optable'
+ optok = optable[type]
+ pasttype = optok['past']
+ pirop = optok['pirop']
+ returns = optok['returns']
+ islvalue = optok['lvalue']
+
+ .local pmc past, iter
+ past = new 'PAST::Op'
+ past.'init'('node'=>node, 'name'=>type, 'pasttype'=>pasttype,
'pirop'=>pirop, 'returns'=>returns)
+
+ $P0 = node.'get_array'()
+ if null $P0 goto iter_end
+ iter = new .Iterator, $P0
+ unless iter goto iter_end
+ $P0[0;'islvalue'] = islvalue
+
+ iter_loop:
+ .local pmc cnode, cpast
+ cnode = shift iter
+ cpast = tree.'get'('past', cnode, 'Lua::Grammar::expr')
+ if null cpast goto iter_loop
+ past.'push'(cpast)
+ if iter goto iter_loop
+ iter_end:
.return (past)
- function:
- $P0 = node['body']
- if null $P0 goto primaryexp
- .return tree.'get'('past', $P0, 'Lua::Grammar::body')
- primaryexp:
- $P0 = node['primaryexp']
- if null $P0 goto error
- .return tree.'get'('past', $P0, 'Lua::Grammar::primaryexp')
- error:
- printerr "Unknown expression\n"
- exit 1
+ past_term:
+ $S0 = node.'find_key'()
+ $P0 = node[$S0]
+ $S0 = concat 'Lua::Grammar::', $S0
+ .return tree.'get'('past', $P0, $S0)
}
-transform past (Lua::Grammar::primaryexp) :language('PIR') {
- .local pmc past, prefixnode, prefixpast
+
+transform past (Lua::Grammar::simple_expression) :language('PIR') {
+ $S0 = node.'find_key'()
+ $P0 = node[$S0]
+ $S0 = concat 'Lua::Grammar::', $S0
+ .return tree.'get'('past', $P0, $S0)
+}
+
+transform past (Lua::Grammar::number) :language('PIR') {
+ .local pmc past
past = new 'PAST::Val'
- prefixnode = node['prefixexp']
- prefixpast = tree.'get'('past', prefixnode, 'Lua::Grammar::prefixnode')
- past.'push'(prefixpast)
+ past.'init'('node'=>node, 'vtype'=>'.LuaNumber', 'name'=>node,
'ctype'=>'i+')
.return (past)
}
-transform past (Lua::Grammar::prefixnode) :language('PIR') {
+transform past (Lua::Grammar::nil) :language('PIR') {
.local pmc past
- past = new 'PAST::Var'
- past.'init'('node'=>node)
+ past = new 'PAST::Val'
+ past.'init'('node'=>node, 'vtype'=>'.Undef', 'name'=>node)
.return (past)
}
-transform past (Lua::Grammar::cond) :language('PIR') {
- .local pmc past
- $P0 = node['expr']
- .return tree.'get'('past', $P0, 'Lua::Grammar::expr')
+transform past (Lua::Grammar::primary_expression) :language('PIR') {
+ $S0 = node.'find_key'()
+ $P0 = node[$S0]
+ $S0 = concat 'Lua::Grammar::', $S0
+ .return tree.'get'('past', $P0, $S0)
}
+transform past (Lua::Grammar::prefix_expression) :language('PIR') {
+ $S0 = node.'find_key'()
+ $P0 = node[$S0]
+ $S0 = concat 'Lua::Grammar::', $S0
+ .return tree.'get'('past', $P0, $S0)
+}
transform past (Lua::Grammar::string) :language('PIR') {
.local pmc result
result = new 'PAST::Val'
- .local string value
quoted_literal:
$P0 = node['quoted_literal']
if null $P0 goto long_string
- value = $P0
- result.'init'('node'=>node, 'vtype'=>'.String', 'name'=>value)
+ $S0 = $P0
+ result.'init'('node'=>node, 'vtype'=>'.String', 'name'=>$S0)
.return (result)
long_string:
$P0 = node['long_string']
if null $P0 goto error
- value = $P0
- result.'init'('node'=>node, 'vtype'=>'.String', 'name'=>value)
+ $S0 = $P0
+ result.'init'('node'=>node, 'vtype'=>'.String', 'name'=>$S0)
.return (result)
error:
printerr "Unknown string\n"
Modified: trunk/languages/lua/src/lua.pg
==============================================================================
--- trunk/languages/lua/src/lua.pg (original)
+++ trunk/languages/lua/src/lua.pg Fri Mar 9 08:18:02 2007
@@ -16,100 +16,100 @@
}
rule block {
- [ <statement> <';'>? ]* [ <laststat> <';'>? ]?
+ [ <statement> <';'>? ]* [ <last_statement> <';'>? ]?
}
rule statement {
- <ifstat>
- | <whilestat>
- | <doblock>
- | <forstat>
- | <repeatstat>
- | <localstat>
- | <exprstat>
- | <funcstat>
+ | <if_stat>
+ | <while_stat>
+ | <do_block>
+ | <for_stat>
+ | <repeat_stat>
+ | <local_stat>
+ | <expression_stat>
+ | <function_stat>
}
-rule funcstat {
- <'function'> <funcname> <body>
+rule function_stat {
+ <'function'> <functionname> <body>
}
-rule laststat {
- <'return'> <explist1>?
- | <'break'>
+rule last_statement {
+ | (<'return'>) <expression_list>?
+ | (<'break'>)
}
-rule doblock {
+rule do_block {
<'do'> <block> <?end>
}
-rule localstat {
- <localfunc> | <localdecl>
+rule local_stat {
+ <local_function> | <local_declaration>
}
-rule exprstat {
- <primaryexp> <assignment>?
+rule expression_stat {
+ <primary_expression> <assignment>?
}
rule assignment {
- <','> <primaryexp> <assignment>
- | <'='> <explist1>
+ | <','> <primary_expression> <assignment>
+ | <'='> <expression_list>
}
-rule whilestat {
- <'while'> <expr1> <?do> <block> <?end>
+rule while_stat {
+ <'while'> <expression> <?do> <block> <?end>
}
-rule repeatstat {
- <'repeat'> <block> <?until> <expr1>
+rule repeat_stat {
+ <'repeat'> <block> <?until> <expression>
}
-rule forbody {
+rule for_body {
<?do> <block> <?end>
}
rule fornum {
- <name> <'='> <expr1> <?comma> <expr1> [ <','> <expr1> ]?
+ <name> <'='> <expression> <?comma> <expression> [ <','> <expression> ]?
}
rule forlist {
- <namelist1> <?in> <explist1>
+ <name_list> <?in> <expression_list>
}
-rule forstat {
- <'for'> [ <fornum> | <forlist> ] <forbody>
+rule for_stat {
+ <'for'> [ <fornum> | <forlist> ] <for_body>
}
-rule ifstat {
- <'if'> <expr1> <?then> <block> <elseifblock>* <elseblock>? <?end>
+rule if_stat {
+ <'if'> <expression> <?then> <block> <elseif_block>* <else_block>? <?end>
}
-rule elseifblock {
- <'elseif'> <expr1> <?then> <block>
+rule elseif_block {
+ <'elseif'> <expression> <?then> <block>
}
-rule elseblock {
+rule else_block {
<'else'> <block>
}
-rule localdecl {
- <'local'> <name> [ <','> <name> ]* [ <'='> <explist1> ]?
+rule local_declaration {
+ <'local'> <name> [ <','> <name> ]* [ <'='> <expression_list> ]?
}
-rule localfunc {
- <'local'> <'function'> <name> <body>
+rule local_function {
+ <'local'> <'function'> <name> <function_body>
}
-rule funcname {
+rule functionname {
<name> [ <'.'> <name> ]* [ <':'> <name> ]?
}
rule index {
- <'['> <expr1> <?closebracket>
+ <'['> <expression> <?closebracket>
}
-rule recfield {
- [ <name> | <index> ] <?assign> <expr1>
+rule record_field {
+ [ <name> | <index> ] <?assign> <expression>
}
rule constructor {
@@ -125,49 +125,49 @@
}
rule tablefield {
- [ <recfield> | <expr> ]*
+ [ <record_field> | <expression> ]*
}
-rule parlist {
- <namelist1> [ <','> <'...'> ]?
+rule parameter_list {
+ | <name_list> [ <','> <'...'> ]?
| <'...'>
}
-rule body {
- <'('> <parlist>? <?closeparen> <block> <?end>
+rule function_body {
+ <'('> <parameter_list>? <?closeparen> <block> <?end>
}
-rule explist1 {
- <expr> [ <','> <expr> ]*
+rule expression_list {
+ <expression> [ <','> <expression> ]*
}
-rule namelist1 {
+rule name_list {
<name> [ <','> <name> ]*
}
-rule funcargs {
- <'('> <explist1>? <?closeparen>
+rule function_args {
+ | <'('> <expression_list>? <?closeparen>
| <constructor>
| <string>
}
-rule prefixexp {
- <name>
- | <'('> <expr1> <?closeparen>
+rule prefix_expression {
+ | <name>
+ | <'('> <expression> <?closeparen>
}
-rule primaryexp {
- <prefixexp>
+rule primary_expression {
+ <prefix_expression>
[ <'.'> <name>
| <index>
- | <':'> <name> <funcargs>
- | <funcargs>
+ | <':'> <name> <function_args>
+ | <function_args>
]*
}
-rule simpleexpr {
- <number>
+rule simple_expression {
+ | <number>
| <string>
| <'nil'>
| <'true'>
@@ -175,7 +175,7 @@
| <'...'>
| <constructor>
| <'function'> <body>
- | <primaryexp>
+ | <primary_expression>
}
@@ -185,25 +185,25 @@
=cut
-rule 'expr' is optable { ... }
+rule 'expression' is optable { ... }
-proto 'term:' is precedence('=') is parsed(&simpleexpr) { ... }
+proto 'term:' is precedence('=') is parsed(&simple_expression) {
... }
proto 'infix:^' is looser('term:')
is assoc('right') { ... }
-proto 'prefix:not' is looser('infix:^') { ... }
-proto 'prefix:#' is equiv('prefix:not') { ... }
-proto 'prefix:-' is equiv('prefix:not') { ... }
-
-proto 'infix:*' is looser('prefix:not') { ... }
-proto 'infix:/' is equiv('infix:*') { ... }
-proto 'infix:%' is equiv('infix:*') { ... }
+proto 'prefix:not' is looser('infix:^') is pirop('not') { ... }
+proto 'prefix:#' is equiv('prefix:not') is pirop('elements') { ... } #
does this work?? it needs an I register
+proto 'prefix:-' is equiv('prefix:not') is pirop('neg') { ... }
+
+proto 'infix:*' is looser('prefix:not') is pirop('mul') { ... }
+proto 'infix:/' is equiv('infix:*') is pirop('div') { ... }
+proto 'infix:%' is equiv('infix:*') is pirop('mod') { ... }
-proto 'infix:+' is looser('infix:*') { ... }
-proto 'infix:-' is equiv('infix:+') { ... }
+proto 'infix:+' is looser('infix:*') is pirop('add') { ... }
+proto 'infix:-' is equiv('infix:+') is pirop('sub') { ... }
-proto 'infix:..' is looser('infix:+')
+proto 'infix:..' is looser('infix:+') is pirop('concat')
is assoc('right') { ... }
proto 'infix:<' is looser('infix:..') { ... }
@@ -266,10 +266,6 @@
<')'> | <syntax_error: ')' expected>
}
-rule expr1 {
- <expr> | <syntax_error: expression expected>
-}
-
=head1 TOKENS
@@ -300,7 +296,7 @@
token number {
- | 0 <[Xx]> <xdigit>+
+ | 0 <[Xx]> <xdigit>+
| [ <digit>+ [ \. <digit>* ]? | \. <digit>+ ]
[ <[Ee]> <[+\-]>? <digit>+ ]?
}
@@ -328,5 +324,6 @@
| <'function'> | <'if'> | <'in'> | <'local'>
| <'nil'> | <'not'> | <'or'> | <'repeat'>
| <'return'> | <'then'> | <'true'> | <'until'>
- | <'while'> ] \b
+ | <'while'> ] \b
}
+
Modified: trunk/languages/lua/src/lua.pir
==============================================================================
--- trunk/languages/lua/src/lua.pir (original)
+++ trunk/languages/lua/src/lua.pir Fri Mar 9 08:18:02 2007
@@ -11,7 +11,7 @@
$P0 = new [ 'HLLCompiler' ]
$P0.'language'('Lua')
$P0.'parsegrammar'('Lua::Grammar')
- $P0.'astgrammar'('ASTGrammar')
+ $P0.'astgrammar'('Lua::PAST::Grammar')
$S0 = "Lua 5.1 on Parrot Copyright (C) 2005-2007, The Perl Foundation.\n"
$P0.'commandline_banner'($S0)