Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class Parser {
  4. private Lexer lex;
  5. private BufferedReader pbr;
  6. private Token look;
  7.  
  8. public Parser(Lexer l, BufferedReader br) {
  9. lex = l;
  10. pbr = br;
  11. move();
  12. }
  13.  
  14. void move() {
  15. look = lex.lexical_scan(pbr);
  16. System.out.println("token = " + look);
  17. }
  18.  
  19. void error(String s) {
  20. throw new Error("near line " + lex.line + ": " + s);
  21. }
  22.  
  23. void match(int t) {
  24. if (look.tag == t) {
  25. if (look.tag != Tag.EOF) move();
  26. } else error("syntax error");
  27. }
  28.  
  29. public void start() {
  30. // ... completare ...
  31. expr();
  32. match(Tag.EOF);
  33. // ... completare ...
  34. }
  35.  
  36. private void expr() {
  37. // ... completare ...
  38. }
  39.  
  40. private void exprp() {
  41. switch (look.tag) {
  42. case '+':
  43. // ... completare ...
  44. }
  45. }
  46.  
  47. private void term() {
  48. // ... completare ...
  49. }
  50.  
  51. private void termp() {
  52. // ... completare ...
  53. }
  54.  
  55. private void fact() {
  56. // ... completare ...
  57. }
  58.  
  59. public static void main(String[] args) {
  60. Lexer lex = new Lexer();
  61. String path = "...path..."; // il percorso del file da leggere
  62. try {
  63. BufferedReader br = new BufferedReader(new FileReader(path));
  64. Parser parser = new Parser(lex, br);
  65. parser.start();
  66. System.out.println("Input OK");
  67. br.close();
  68. } catch (IOException e) {e.printStackTrace();}
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement