简体   繁体   English

“输入末尾解析错误”,但我确定方括号正确。 (在C中)

[英]“parse error at end of input”, but I'm sure my brackets are correct. (in C)

I'm pretty sure my brackets are matched up correctly, but I'm getting the error "parse error at end of input" No matter how many or few brackets I attach to the end of this program. 我很确定我的括号正确匹配,但是无论我在程序末尾附加多少括号,都会收到错误“输入末尾解析错误”。 Since all of the Google results for this error say that the fix lies in the brackets, I'm at a loss for what else it could be. 由于针对该错误的所有Google结果都指出,解决方法位于方括号中,因此我不知所措。 Could someone point out my silly little mistake for me? 有人可以为我指出我愚蠢的小错误吗? :) :)

#include <stdio.h>
#include "/user/cse320/Projects/project06.support.h"
#include "/user/cse320/Projects/project06.hardware.h"

void execute()
{
  unsigned long int IRdecode;
  IRdecode = IR;
  IRdecode >> 30;

  if ( IRdecode == 0 )
  {

    unsigned int _reg = IR;
    unsigned int _imm = IR;

    _reg << 2;
    _reg >> 27;

    _imm << 9;

    write_reg_file( _reg, _imm );
  }

  if ( IRdecode == 00000002 )
  {

    unsigned int _op3 = IR;
    unsigned int _rd = IR;
    unsigned int _rs1 = IR;
    _op3 << 7;
    _op3 >> 26;

    _rd << 2;  
    _rd >> 30;

    _rs1 << 13;
    _rs1 >> 27;

    if ( _op3 == 00000001 ){
      //AND }
    if ( _op3 == 00000002 ){
      //OR } 
    if ( _op3 == 00000003 ){
      //XOR } 
    if ( _op3 == 00000005 ){
      //ANDN }
    if ( _op3 == 00000006 ){
      //ORN } 
    if ( _op3 == 00000007 ){
      //XNOR }
  } 
} 

you are using //AND } for comment which will comment every thing in same line, results } to be commented. 您正在使用//AND }用于将评论每一件事在同一直线上,结果注释}进行评论。

CODE: 码:

if ( _op3 == 00000001 ){
  //AND }                //here } will be commented.

You should use like this 你应该这样使用

 if ( _op3 == 00000001 ){
  //AND 
 }                          //now OK

OR 要么

 if ( _op3 == 00000001 ){
  /*AND*/  }               //OK, as well

Unless there is something strange going on, I think there is also another problem with your code (other than the problem with the comments): 除非发生奇怪的事情,否则我认为您的代码还会有另一个问题(除了注释问题之外):

_op3 << 7;
_op3 >> 26;

_rd << 2;  
_rd >> 30;

_rs1 << 13;
_rs1 >> 27;

These bitshift operations are completely useless because the result is discarded. 这些位移位操作完全没有用,因为结果被丢弃了。 The << operator is just like the + operator in the way that it takes two operands and produces a result. <<运算符就像+运算符一样,它需要两个操作数并产生结果。 What would you expect the following to do? 您期望以下各项做什么?

i + 4;
2 + 4;
1 + 9;

I think what you want is the compound operators: 我认为您想要的是复合运算符:

_op3 <<= 7;

This is equivalent to: 这等效于:

_op3 = op3 << 7;

It looks like the closing braces of the if statements are accidentally commented out: 好像if语句的右花括号被意外注释掉了:

if ( _op3 == 00000001 ){
  //AND }

This may not be your only problem (since you say adding lots of braces at the end of the program does not help) but in the statements like this ... 这可能不是您唯一的问题(因为您说在程序末尾添加许多大括号无济于事),而是在这样的语句中...

if ( _op3 == 00000001 ){
  //AND }

// comments run to the end of the line, therefore you have commented out the close brace . //注释一直到行尾,因此您已经注释掉了右括号 Try using /*AND*/ and so forth, instead. 尝试使用/*AND*/等。

If that doesn't cure the problem, please post preprocessed source code, which you can get with gcc -E . 如果那不能解决问题,请发布预处理的源代码,您可以使用gcc -E获得该源代码。 Warning: this will produce a very large file, which you should cut down to the smallest thing you can manage that still causes the problem. 警告:这将产生一个非常大的文件,您应该将其缩减为可以解决问题的最小文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的程序有 AddressSanitizer 错误,但我不知道如何阅读 - My program has AddressSanitizer error but I'm not sure how to read it 我想确保我的程序是正确的,这是 c 编程 - I want to make sure my program is correct this is c programming C语言 - 这可能是一个段错误错误,但我不确定? - C Language - This is probably a seg fault error, but i'm not sure? 输入末尾的预期声明或声明。 我算出了正确数量的方括号 - Expected declaration or statement at end of input. I counted the correct amount of brackets 我对 C 中的语法有疑问。我不太确定程序中的指针和 arrays - I have problems with the syntax in C. I'm not so sure about the pointers and the arrays in my programm 它在最后印刷了额外的零,我不知道为什么 - Its printing a extra zero at the end and I'm not sure why 我不确定为什么我在 C 中的代码会免费给我一个分段错误,有什么想法吗? - I'm not sure why my code in C is giving me a segmentation fault at free, any ideas? 当所有方括号都匹配时,输入结尾处的语法错误 - Syntax error at the end of input when all brackets match 我的语言再次输入时出现错误 - I'm receiving an error when giving my language a second input 我对 C 中的 EOF(文件结尾)的理解是否正确? - Is my understanding of EOF (end of file) in C correct?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM