--- /dev/null
+/*
+ * @LANG: indep
+ */
+int i;
+int c;
+%%
+
+%%{
+ machine foo;
+
+ action testi {i > 0}
+ action inc {
+ i = i - 1;
+ c = fc;
+ prints "item: ";
+ printi c;
+ prints "\n";
+ }
+
+ count = [0-9] @{
+ i = fc - '0';
+ prints "count: ";
+ printi i;
+ prints "\n";
+ };
+
+ sub =
+ count # record the number of digits
+ ( digit when testi @inc )* outwhen !testi;
+
+ main := sub sub '\n';
+}%%
+
+/* _____INPUT_____
+"00\n"
+"019\n"
+"190\n"
+"1719\n"
+"1040000\n"
+"104000a\n"
+"104000\n"
+_____INPUT_____ */
+/* _____OUTPUT_____
+count: 0
+count: 0
+ACCEPT
+count: 0
+count: 1
+item: 57
+ACCEPT
+count: 1
+item: 57
+count: 0
+ACCEPT
+count: 1
+item: 55
+count: 1
+item: 57
+ACCEPT
+count: 1
+item: 48
+count: 4
+item: 48
+item: 48
+item: 48
+item: 48
+ACCEPT
+count: 1
+item: 48
+count: 4
+item: 48
+item: 48
+item: 48
+FAIL
+count: 1
+item: 48
+count: 4
+item: 48
+item: 48
+item: 48
+FAIL
+_____OUTPUT_____ */
| '{ [NL] [IN] [c_statements] [EX] '} [NL]
end define
+redefine cond_action_stmt
+ 'action [id] '{ [al_expr] '} [NL]
+ | 'action [id] '{ [c_expr] '} [NL]
+end redefine
+
+
rule boolTypes
replace [al_type_decl]
'bool
'{ CStmts '}
end rule
+rule condTransC
+ replace [cond_action_stmt]
+ 'action Id [id] '{ AlExpr [al_expr] '}
+ construct OptCExpr [opt c_expr]
+ _ [alExprToC AlExpr]
+ deconstruct OptCExpr
+ CExpr [c_expr]
+ by
+ 'action Id '{ CExpr '}
+end rule
+
function langTransC
replace [program]
Definitions [repeat action_lang_stmt]
CDefinitions
'%%
CInitializations
- RagelDef [actionTransC]
+ RagelDef [actionTransC] [condTransC]
end function
function main
| '{ [NL] [IN] [java_statements] [EX] '} [NL]
end define
+redefine cond_action_stmt
+ 'action [id] '{ [al_expr] '} [NL]
+ | 'action [id] '{ [java_expr] '} [NL]
+end redefine
+
+
function clearUnion Type [java_type_decl] Id [id]
replace [opt union]
Union [union]
'{ JavaStmts '}
end rule
+rule condTransJava
+ replace [cond_action_stmt]
+ 'action Id [id] '{ AlExpr [al_expr] '}
+ construct OptJavaExpr [opt java_expr]
+ _ [alExprToJava AlExpr]
+ deconstruct OptJavaExpr
+ JavaExpr [java_expr]
+ by
+ 'action Id '{ JavaExpr '}
+end rule
+
rule machineName
replace $ [machine_stmt]
'machine _ [id] ';
construct JavaInitializations [repeat java_lang_stmt]
_ [alToJava Initializations]
construct NewRagelDef [ragel_def]
- RagelDef [actionTransJava] [machineName]
+ RagelDef [actionTransJava] [condTransJava] [machineName]
import ArrayInits [java_statements]
ArrayInitStmts [repeat java_lang_stmt]
by
| '{ [NL] [IN] [ruby_statements] [EX] '} [NL]
end define
+redefine cond_action_stmt
+ 'action [id] '{ [al_expr] '} [NL]
+ | 'action [id] '{ [ruby_expr] '} [NL]
+end redefine
+
function initDecl1 VarDecl [al_variable_decl]
deconstruct VarDecl
'bool Id [id] ';
'{ RubyStmts '}
end rule
+rule condTransRuby
+ replace [cond_action_stmt]
+ 'action Id [id] '{ AlExpr [al_expr] '}
+ construct OptRubyExpr [opt ruby_expr]
+ _ [alExprToRuby AlExpr]
+ deconstruct OptRubyExpr
+ RubyExpr [ruby_expr]
+ by
+ 'action Id '{ RubyExpr '}
+end rule
+
rule lowercaseMachine
replace $ [machine_stmt]
'machine Id [id] ';
construct RubyInitializations [repeat ruby_lang_stmt]
_ [alToRuby Initializations]
construct NewRagelDef [ragel_def]
- RagelDef [actionTransRuby] [lowercaseMachine]
+ RagelDef [actionTransRuby] [condTransRuby] [lowercaseMachine]
import ArrayInits [ruby_statements]
ArrayInitStmts [repeat ruby_lang_stmt]
by
end define
define al_expr_op
- '= | '+ | '- | '* | '/ | '== | '<= | '>=
+ '= | '+ | '- | '* | '/ | '== | '<= | '>= | '< | '>
end define
define al_term