Skip to content

Instantly share code, notes, and snippets.

@andfoy
Created February 12, 2016 16:41
Show Gist options
  • Select an option

  • Save andfoy/d04f3d37b37018d23b12 to your computer and use it in GitHub Desktop.

Select an option

Save andfoy/d04f3d37b37018d23b12 to your computer and use it in GitHub Desktop.
/**
* JavaCC template file created by SF JavaCC plugin 1.5.17+ wizard for JavaCC 1.5.0+
*/
options
{
static = false;
DEBUG_PARSER = true;
}
PARSER_BEGIN(NuevoParser)
package uniandes.teolen.parserJavaCC.newParser;
public class NuevoParser
{
}
PARSER_END(NuevoParser)
SKIP :
{
" "
| "\r"
| "\t"
| "\n"
}
TOKEN : // OPERATORS
{
< PLUS : "+" >
| < MINUS : "-" >
| < MULTIPLY : "*" >
| < DIVIDE : "/" >
}
TOKEN :
{
< DIGIT : ["1"-"9"] >
| < CONSTANT : ("0" | < DIGIT >)+"E"("0" | < DIGIT >)+ >
| < IM_UNIT : "i">
| < #LOWER : ["a"-"z"] >
| < #UPPER : ["A"-"Z"] >
| < #CHAR : (< LOWER > | < UPPER >) >
| < VAR : < CHAR > (< CHAR > | "_" | "0" | < DIGIT >)*>
}
int one_line() :
{}
{
exp() ";"
{
return 0;
}
| ";"
{
return 1;
}
}
void exp() :
{}
{
term()
(
(
< PLUS >
| < MINUS >
)
term()
)*
}
void term() :
{}
{
fact()
(
(
< MULTIPLY >
| < DIVIDE >
)
fact()
)*
}
void fact() :
{}
{
(< MINUS >)? (variable() |complex()|"(" exp() ")" | frac() )
}
void frac() :
{}
{
"<" ( < PLUS > | < MINUS > )? ("0" | < DIGIT >)+ ":" ( < PLUS > | < MINUS > )? < DIGIT >("0" | < DIGIT >)*">"
}
void complex() :
{}
{
(< CONSTANT > | ("0" | < DIGIT >)+)(","(< CONSTANT > | ("0" | < DIGIT >)+)< IM_UNIT >)?
}
void variable() :
{}
{
< VAR >(("["exp_non_complex()"]")+)?
}
void exp_non_complex() :
{}
{
term_non_complex()
(
(
< PLUS >
| < MINUS >
)
term_non_complex()
)*
}
void term_non_complex() :
{}
{
fact_non_complex()
(
(
< MULTIPLY >
| < DIVIDE >
)
fact_non_complex()
)*
}
void fact_non_complex() :
{}
{
(< MINUS >)? (("0" | < DIGIT >)+ | variable() |"(" exp_non_complex() ")")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment